<!-- 雷达散点图 -->
<template>
  <div ref="chartRef" :style="{ width, height }"></div>
</template>
<script lang="ts" setup>
  import { Ref, ref, watch } from 'vue';
  import echarts from '/@/utils/lib/echarts';
  import { useECharts } from '/@/hooks/web/useECharts';

  const props = defineProps({
    loading: Boolean,
    width: {
      type: String as PropType<string>,
      default: '100%',
    },
    height: {
      type: String as PropType<string>,
      default: '300px',
    },

    seriesVal: {
      type: Object,
      default: () => {},
    },
  });

  const chartRef = ref<HTMLDivElement | null>(null);
  const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);

  watch(
    () => props.loading,
    () => {
      if (props.loading) {
        return;
      }
      const {Xdata , seriesValue} = props.seriesVal
      if (seriesValue && seriesValue.length === 0) {
        setOptions({
          title: {
            textStyle: {
              color: 'grey',
              fontSize: 20,
            },
            text: '暂无数据',
            left: 'center',
            top: 'center',
          },
        });
      } else {
        setOptions({
          grid: {
            top: 10,
            left: 10,
            right: 20,
            bottom: 0,
            containLabel: true,
          },
          color: ['#5189F8'],
          tooltip: {},
          radar: {
            axisName: {
                fontSize: 14,
                color: '#6D7278',
            },
            axisLine: {
                lineStyle: {
                    color: '#ebeef3',
                },
            },
            // center:['50%','50%'],
            // radius:'40%',
            triggerEvent: false,
            indicator: Xdata
          },
          series: [
            {
                name: '',
                type: 'radar',
                symbolSize: 7,
                lineStyle: {
                    width: 2
                },
                data: [
                  {
                    value: seriesValue,
                    name: ''
                  }
                ],
            },
          ],
          ...props.seriesVal,
        });
      }
    },
    { immediate: true },
  );
</script>
